﻿// E-Book Copier
// Copyright (C) 2009 Chuan-Gen Fan
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Project: http://code.google.com/p/ebookcopier/
// Contact Author:
//    website: http://chuangen.name/
// e-mail/msn: chuangen@live.cn

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace EbookCopier
{
    /// <summary>
    /// PDF 文档属性设置 窗体。
    /// </summary>
    public partial class PdfSetForm : Form
    {
        PdfSettings settings = null;
        /// <summary>
        /// 初始化类 <see cref="PdfSetForm"/> 的新实例。
        /// </summary>
        /// <param name="settings">关联的 PdfSettings 实例</param>
        public PdfSetForm(PdfSettings settings)
        {
            if (settings == null)
                throw new ArgumentNullException("settings", "settings 不能为空。");
            InitializeComponent();

            this.settings = settings;

            btnOK.Click += new EventHandler(btnOK_Click);
            btnCancel.Click += new EventHandler(btnCancel_Click);
        }
        void btnOK_Click(object sender, EventArgs e)
        {
            settings.Title = txtTitle.Text;
            settings.Author = txtAuthor.Text;
            settings.Subject = txtSubject.Text;
            settings.Keywords = txtKeywords.Text;

            settings.LeftMargin =(float)numLeftMargin.Value;
            settings.RightMargin = (float)numRightMargin.Value;
            settings.TopMargin = (float)numTopMargin.Value;
            settings.BottomMargin = (float)numBottomMargin.Value;

            settings.Header = txtHeader.Text;
            settings.Footer = txtFooter.Text;
            this.DialogResult = DialogResult.OK;
        }
        void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        /// <summary>
        /// 引发 <see cref="E:System.Windows.Forms.Form.Load"></see> 事件。
        /// </summary>
        /// <param name="e">包含事件数据的 <see cref="T:System.EventArgs"></see>。</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            txtTitle.Text = settings.Title;
            txtAuthor.Text = settings.Author;
            txtSubject.Text = settings.Subject;
            txtKeywords.Text = settings.Keywords;

            numLeftMargin.Value = (decimal)settings.LeftMargin;
            numRightMargin.Value = (decimal)settings.RightMargin;
            numTopMargin.Value = (decimal)settings.TopMargin;
            numBottomMargin.Value =(decimal) settings.BottomMargin;

            txtHeader.Text = settings.Header;
            txtFooter.Text = settings.Footer;
        }
    }
}